<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="root">

    </div>
</body>
<script src="../react@17.js"></script>
<script src="../react-dom@17.js"></script>
<script src="../babel.js"></script>
<script type="text/babel">
    class App extends React.Component{
        constructor(){
            super();
            // 状态的另一种写法
            this.state= {
                num:0,
                name:"李四"
            }
        }
        render(){
            let {num,name} = this.state;
            return (
                <div>
                    <h2>状态再体验----{num}---{name}</h2>    
                    <button onClick={()=>{
                        // 更新状态参数为一个函数
                        this.setState((state)=>{
                            return {
                                num:state.num+1
                            }
                        })
                        this.setState((state)=>{
                            return {
                                num:state.num+1
                            }
                        })
                        this.setState((state)=>{
                            return {
                                num:state.num+1
                            }
                        })
                    }}>++</button>
                    <button onClick={()=>{
                        this.setState((state)=>{
                            return {
                                name:"张三",
                                num:100
                            }
                        })
                    }}>改变name</button>
                </div>
            )
        }
    }

    ReactDOM.render(<App/>,document.getElementById("root"))
</script>
</html>